﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.BLL.BackdropForm;
using MS.InformationManagement.DAL.RecordCenter;

namespace MS.InformationManagement.Presenter.BackdropForm
{
    public class BackdropFormPresenter : BasePresenter<IBackdropFormView>
    {
        public BackdropFormPresenter(IBackdropFormView view) : base(view) { }

        public void Add()
        {
            if (View.SelectedParent == null && BackdropFormBLL.PrimaryBackdropAlreadyExists()) { throw new Exception("Ya existe un fondo padre en la plataforma"); }
            BackdropFormBLL.AddBackDrop(View.Title, View.Code, View.Version, View.SelectedParent);
        }

        public void Update()
        {
            if (View.SelectedParent == null && BackdropFormBLL.PrimaryBackdropAlreadyExists(View.ItemID.Value)) { throw new Exception("Ya existe un fondo padre en la plataforma"); }
            BackdropFormBLL.UpdateBackDrop(View.ItemID.Value, View.Title, View.Code, View.Version, View.SelectedParent);
        }

        public void HandleLoad()
        {
            View.Backdrops = BackdropFormBLL.GetBackDrops();
            if (View.ItemID.HasValue)
            {
                FondosFondo entity = BackdropFormBLL.GetBackdrop(View.ItemID.Value);
                View.Title = entity.Title;
                View.SelectedParent = entity.FondoAlQuePertenece;
                View.Version = entity.VersiónTablaDeRetención;
                View.Code = entity.Código;
            }
        }

    }
}
